public class MyQueue {
    public static class LinkedNode{
        public int val;
        public LinkedNode prev;
        public LinkedNode next;

        public LinkedNode(int val) {
            this.val = val;
        }
    }
    LinkedNode first;
    LinkedNode last;
    public int size;
    //入队列——向双向链表位置插入新节点
    public  void offer(int data){
        LinkedNode node=new LinkedNode(data);
        if (first==null){
            first=node;
            last=node;
        }else{
            last.next=node;
            node.prev=last;
            last=node;
        }
        size++;
    }
    //出队列——将双向链表第一个节点删除
    public int poll(){
        if(first==null){
            return -1;
        }
        int data=first.val;
        if (first.next==null){
            first=null;
            last=null;
        }else{
            first=first.next;
            first.prev=null;
        }
        size--;
        return data;
    }
    //获取头元素——获取链表中的第一个节点的值域
    public int peek(){
        if (first==null){
            return -1;
        }
        return first.val;
    }
    public int sise(){
        return size;
    }
    public boolean isEmpty(){
    return size==0;
    }
    public void print(){
        LinkedNode cur=first;
        while (cur!=null){
            System.out.print(cur.val+" ");
            cur=cur.next;
        }
        System.out.println();
    }
}
